package com.zbl.zblproject.core.utils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author youlanqiang
 * @version 1.0
 * @date 2018/11/12
 */
public class NumberUtil {


    public static BigDecimal divide(final BigDecimal n1, final BigDecimal n2){
        if(n2 == null || n2.doubleValue() == 0.0){
            return BigDecimal.ZERO;
        }
        return n1.divide(n2, 2, RoundingMode.HALF_DOWN);
    }

    public static int computer(String str){
        Pattern pattern = Pattern.compile("[\\d]+");
        Matcher matcher = pattern.matcher(str);
        int result = 1;
        while(matcher.find()){
            result *= Integer.parseInt(matcher.group());
        }
        return result;
    }

}
